<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="5">
          <a-col :md="4" :sm="6">
            <a-form-item :label="$t('systemManagement.project')">
              <a-select v-model="queryParam.projectCode"  v-decorator="[ 'projectCode']" :placeholder="$t('base.pleaseChoose')">
                <a-select-option v-for="item in projectList" :key="item.id" :value="item.code">
                  {{item.name}}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="6">
          <a-form-item :label="$t('light.lightPoleType')" >
            <j-dict-select-tag   v-model="queryParam.lightPoleType"   placeholder="$t('base.pleaseChoose')" dictCode="glr_light_pole_type"/>
          </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('base.query')}}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('base.reset')}}</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAddLight" type="primary" icon="plus">{{$t('base.add')}}</a-button>
      <a-button type="primary" icon="download" @click="customUploadFile('import_light_pole.xls')">{{$t('base.exportFile')}}</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">{{$t('base.importFile')}}</a-button>
      </a-upload>
      <a-button @click="bindingData1" type="primary" icon="plus">{{$t('light.updateCoordinate')}}</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>{{$t('base.del')}}</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">{{$t('base.batchOperation')}}<a-icon type="down" /></a-button>
      </a-dropdown>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{fixed:true,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <img :src="getAvatarView(record.currentWorkStatus)"/>
          </div>
        </template>


        <template slot="memoslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <j-ellipsis :length="10" :value="record.memo"/>
          </div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">{{$t('base.edit')}}</a>

          <a-divider type="vertical"/>
          <a @click="bindingData(record)"><a-icon type="setting"/> {{$t('light.relevanceEquipment')}}</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">{{$t('base.more')}} <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm :title="$t('base.confirmDelete')" @confirm="() => handleDelete(record.id)">
                  <a> <a-icon type="delete" /> {{$t('base.del')}} </a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                <a @click="updateLg(record)">{{$t('light.updateCoordinate')}}</a>
              </a-menu-item>

            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <glrLightPole-modal ref="modalForm" @ok="modalFormOk"></glrLightPole-modal>
    <glr-light-l-g ref="glrLightLG" @ok="modalFormOk"></glr-light-l-g>
    <glr-light-pole-device-list ref="glrLightPoleDeviceList"></glr-light-pole-device-list>
    <glr-light-pole-gis ref="glrLightPoleGis" @ok="modalFormOk"></glr-light-pole-gis>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import GlrLightPoleModal from './modules/GlrLightPoleModal'
  import { httpAction } from '@/api/manage'
  import GlrLightPoleDeviceList from "./GlrLightPoleDeviceList";
  import GlrLightLG from "./modules/GlrLightLG";
  import JInput from '@/components/jeecg/JInput'
  import JEllipsis from "@/components/jeecg/JEllipsis"
  import GlrLightPoleGis from "./modules/GlrLightPoleGis";

  export default {
    name: "GlrLightPoleList",
    mixins:[JeecgListMixin],
    components: {
      GlrLightPoleGis,
      GlrLightPoleDeviceList,
      GlrLightPoleModal,
      GlrLightLG,
      JInput,
      JEllipsis
    },
    data () {
      return {
        description: '路灯灯杆管理页面',
        dropTrigger: '',
        gateWayTree:[],
        autoExpandParent:true,
        defaultExpandParent:true,
        iExpandedKeys:[],
        isorter:{column: 'project_code,code,create_time', order: 'desc,asc,asc'},
        gateWayCode:'',
        projectList:[],

        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:this.$t('systemManagement.project'),
            align:"center",
            dataIndex: 'projectName'
          },
          {
            title:this.$t('base.code'),
            align:"center",
            dataIndex: 'code'
          },
          {
            title: this.$t('base.description'),
            align: "center",
            dataIndex: 'memo',
            scopedSlots: {customRender: "memoslot"}
          },
          {
            title: this.$t('light.lightPoleType'),
            align: "center",
            dataIndex: 'lightPoleType_dictText'
          },
          {
            title: this.$t('base.operation'),
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/glr/glrLightPole/list",
          delete: "/glr/glrLightPole/delete",
          deleteBatch: "/glr/glrLightPole/deleteBatch",
          exportXlsUrl: "/glr/glrLightPole/exportXls",
          importExcelUrl: "glr/glrLightPole/importExcel",
          getProjectList: "/glr/glrProject/getProject",
        },
        dictOptions:{
        },
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    created(){
      const that = this;
      httpAction(that.url.getProjectList,{},"post").then((res)=>{
        if(res.success){
          that.projectList=res.result;
        }else{
          that.$message.warning(res.message);
        }
      }).finally(() => {
        that.confirmLoading = false;
      });
    //  this.isorter={column: 'project_code,code,create_time', order: 'desc,asc,asc'}
    },
    methods: {
      radioShow(record,type) {
        this.$refs.glrLightPoleMemberRadioList.edit(record,type);
      },
      getAvatarView: function (status) {
        if (status == 'Y') {
          return require('@/assets/img/zaixian.png');
        } else {
          return require('@/assets/img/lixian.png');
        }
      },
      setThisExpandedKeys(node) {
        if (node.children && node.children.length > 0) {
          this.iExpandedKeys.push(node.key)
          for (let a = 0; a < node.children.length; a++) {
            this.setThisExpandedKeys(node.children[a])
          }
        }
      },
      onSelect(selectedKeys, e) {
        var record = e.node.dataRef;
        this.queryParam.gateWayCode=record.key;
        this.gateWayCode=record.key;
        this.loadData();
      },
      handleAddLight(){
        this.$refs.modalForm.add(this.queryParam.gateWayCode);
        this.$refs.modalForm.title = this.$t('base.add');
        this.$refs.modalForm.disableSubmit = false;
      },
      updateLg(record){
        this.$refs.glrLightLG.edit(record,'3');
      },
      bindingData(record){
        this.$refs.glrLightPoleDeviceList.edit(record);
      },
      bindingData1(){
        this.$refs.glrLightPoleGis.edit();
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>